home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / tty32.zip / TTY.H < prev    next >
C/C++ Source or Header  |  1992-10-16  |  7KB  |  258 lines

  1. //---------------------------------------------------------------------------
  2. //
  3. //  Module: tty.h
  4. //
  5. //  Purpose:
  6. //     This is the header file for the TTY sample.
  7. //
  8. //  Development Team:
  9. //     Bryan A. Woodruff
  10. //
  11. //  History:   Date       Author      Comment
  12. //              5/ 9/91   BryanW      Wrote it.
  13. //
  14. //---------------------------------------------------------------------------
  15. //
  16. //  Written by Microsoft Product Support Services, Windows Developer Support.
  17. //  Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  18. //
  19. //---------------------------------------------------------------------------
  20.  
  21. #define USECOMM      // yes, we need the COMM API
  22.  
  23. //#undef NO_STRICT    // be bold!
  24.  
  25. #define HINSTANCE HANDLE
  26.  
  27. #ifndef WIN32
  28. #define WIN31        // this is a Windows 3.1 application
  29. #endif
  30.  
  31. #include <windows.h>
  32. #include <commdlg.h>
  33. #include <string.h>
  34.  
  35. #include "version.h"
  36. #include "resource.h"
  37.  
  38. // constant definitions
  39.  
  40. #ifdef WIN32
  41. #define GWL_NPTTYINFO        0
  42. #define TTYEXTRABYTES        sizeof( LONG )
  43. #else
  44. #define GWW_NPTTYINFO        0
  45. #define TTYEXTRABYTES        sizeof( WORD )
  46. #endif
  47.  
  48. #define ABOUTDLG_USEBITMAP  1
  49.  
  50. #define ATOM_TTYINFO       0x100
  51.  
  52. // hard coded maximum number of ports for device under Win32
  53.  
  54. #ifdef WIN32
  55. #define MAXPORTS        4
  56. #endif
  57.  
  58. // terminal size
  59.  
  60. #define MAXROWS         25
  61. #define MAXCOLS         80
  62.  
  63. #define MAXBLOCK        80
  64.  
  65. #define MAXLEN_TEMPSTR  81
  66.  
  67. #define RXQUEUE         4096
  68. #define TXQUEUE         4096
  69.  
  70. // cursor states
  71.  
  72. #define CS_HIDE         0x00
  73. #define CS_SHOW         0x01
  74.  
  75. // Flow control flags
  76.  
  77. #define FC_DTRDSR       0x01
  78. #define FC_RTSCTS       0x02
  79. #define FC_XONXOFF      0x04
  80.  
  81. // ascii definitions
  82.  
  83. #define ASCII_BEL       0x07
  84. #define ASCII_BS        0x08
  85. #define ASCII_LF        0x0A
  86. #define ASCII_CR        0x0D
  87. #define ASCII_XON       0x11
  88. #define ASCII_XOFF      0x13
  89.  
  90. // we are going to fake the CN_EVENT notifications using another
  91. // thread in Win32
  92.  
  93. #ifdef WIN32
  94. #define CN_EVENT 0x04
  95. #endif
  96.  
  97. // data structures
  98.  
  99. typedef struct tagTTYINFO
  100. {
  101. #ifdef WIN32
  102.    HANDLE  idComDev ;
  103. #else
  104.    int     idComDev ;
  105. #endif
  106.    BYTE    bPort, abScreen[ MAXROWS * MAXCOLS ] ;
  107.    BOOL    fConnected, fXonXoff, fLocalEcho, fNewLine, fAutoWrap,
  108.            fUseCNReceive, fDisplayErrors;
  109.    BYTE    bByteSize, bFlowCtrl, bParity, bStopBits ;
  110. #ifdef WIN32
  111.    DWORD   dwBaudRate ;
  112.    WORD    wCursorState ;
  113. #else
  114.    WORD    wBaudRate, wCursorState ;
  115. #endif
  116.    HFONT   hTTYFont ;
  117.    LOGFONT lfTTYFont ;
  118.    DWORD   rgbFGColor ;
  119.    int     xSize, ySize, xScroll, yScroll, xOffset, yOffset,
  120.            nColumn, nRow, xChar, yChar ;
  121. #ifdef WIN32
  122.    HANDLE      hPostEvent, hWatchThread, hWatchEvent ;
  123.    HWND        hTermWnd ;
  124.    DWORD       dwThreadID ;
  125.    OVERLAPPED  osWrite, osRead ;
  126. #endif
  127.  
  128. } TTYINFO, NEAR *NPTTYINFO ;
  129.  
  130. // macros ( for easier readability )
  131.  
  132. #ifdef WIN32
  133. #define GETHINST( x )  ((HINSTANCE) GetWindowLong( x, GWL_HINSTANCE ))
  134. #define GETNPTTYINFO( x ) ((NPTTYINFO) GetWindowLong( x, GWL_NPTTYINFO ))
  135. #define SETNPTTYINFO( x, y ) SetWindowLong( x, GWL_NPTTYINFO, (LONG) y )
  136. #else
  137. #define GETHINST( x )  ((HINSTANCE) GetWindowWord( x, GWW_HINSTANCE ))
  138. #define GETNPTTYINFO( x ) ((NPTTYINFO) GetWindowWord( x, GWW_NPTTYINFO ))
  139. #define SETNPTTYINFO( x, y ) SetWindowWord( x, GWW_NPTTYINFO, (WPARAM) y )
  140. #endif
  141.  
  142. #define COMDEV( x ) (x -> idComDev)
  143. #define PORT( x )   (x -> bPort)
  144. #define SCREEN( x ) (x -> abScreen)
  145. #define CONNECTED( x ) (x -> fConnected)
  146. #define XONXOFF( x ) (x -> fXonXoff)
  147. #define LOCALECHO( x ) (x -> fLocalEcho)
  148. #define NEWLINE( x ) (x -> fNewLine)
  149. #define AUTOWRAP( x ) (x -> fAutoWrap)
  150. #define BYTESIZE( x ) (x -> bByteSize)
  151. #define FLOWCTRL( x ) (x -> bFlowCtrl)
  152. #define PARITY( x ) (x -> bParity)
  153. #define STOPBITS( x ) (x -> bStopBits)
  154. #ifdef WIN32
  155. #define BAUDRATE( x ) (x -> dwBaudRate)
  156. #else
  157. #define BAUDRATE( x ) (x -> wBaudRate)
  158. #endif
  159. #define CURSORSTATE( x ) (x -> wCursorState)
  160. #define HTTYFONT( x ) (x -> hTTYFont)
  161. #define LFTTYFONT( x ) (x -> lfTTYFont)
  162. #define FGCOLOR( x ) (x -> rgbFGColor)
  163. #define XSIZE( x ) (x -> xSize)
  164. #define YSIZE( x ) (x -> ySize)
  165. #define XSCROLL( x ) (x -> xScroll)
  166. #define YSCROLL( x ) (x -> yScroll)
  167. #define XOFFSET( x ) (x -> xOffset)
  168. #define YOFFSET( x ) (x -> yOffset)
  169. #define COLUMN( x ) (x -> nColumn)
  170. #define ROW( x ) (x -> nRow)
  171. #define XCHAR( x ) (x -> xChar)
  172. #define YCHAR( x ) (x -> yChar )
  173. #define USECNRECEIVE( x ) (x -> fUseCNReceive)
  174. #define DISPLAYERRORS( x ) (x -> fDisplayErrors)
  175.  
  176. #ifdef WIN32
  177. #define POSTEVENT( x ) (x -> hPostEvent)
  178. #define TERMWND( x ) (x -> hTermWnd)
  179. #define HTHREAD( x ) (x -> hWatchThread)
  180. #define THREADID( x ) (x -> dwThreadID)
  181. #define WRITE_OS( x ) (x -> osWrite)
  182. #define READ_OS( x ) (x -> osRead)
  183. #endif
  184.  
  185. #define SET_PROP( x, y, z )  SetProp( x, MAKEINTATOM( y ), z )
  186. #define GET_PROP( x, y )     GetProp( x, MAKEINTATOM( y ) )
  187. #define REMOVE_PROP( x, y )  RemoveProp( x, MAKEINTATOM( y ) )
  188.  
  189. // global stuff
  190.  
  191. char     gszTTYClass[] = "TTYWndClass" ;
  192. char     gszAppName[] = "TTY" ;
  193. HANDLE   ghAccel ;
  194.  
  195. DWORD    BaudTable[] =
  196.          {
  197.             CBR_110, CBR_300, CBR_600, CBR_1200, CBR_2400,
  198.             CBR_4800, CBR_9600, CBR_14400, CBR_19200, CBR_38400,
  199.             CBR_56000, CBR_128000, CBR_256000
  200.          } ;
  201.  
  202. DWORD    ParityTable[] =
  203.          {
  204.             NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY
  205.          } ;
  206.  
  207. DWORD    StopBitsTable[] =
  208.          {
  209.             ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS
  210.          } ;
  211.  
  212. // CRT mappings to NT API
  213.  
  214. #define _fmemset   memset
  215. #define _fmemmove  memmove
  216.  
  217. // function prototypes (private)
  218.  
  219. BOOL NEAR InitApplication( HANDLE ) ;
  220. HWND NEAR InitInstance( HANDLE, int ) ;
  221. LRESULT NEAR CreateTTYInfo( HWND ) ;
  222. BOOL NEAR DestroyTTYInfo( HWND ) ;
  223. BOOL NEAR ResetTTYScreen( HWND, NPTTYINFO ) ;
  224. BOOL NEAR KillTTYFocus( HWND ) ;
  225. BOOL NEAR PaintTTY( HWND ) ;
  226. BOOL NEAR SetTTYFocus( HWND ) ;
  227. BOOL NEAR ScrollTTYHorz( HWND, WORD, WORD ) ;
  228. BOOL NEAR ScrollTTYVert( HWND, WORD, WORD ) ;
  229. BOOL NEAR SizeTTY( HWND, WORD, WORD ) ;
  230. BOOL NEAR ProcessTTYCharacter( HWND, BYTE ) ;
  231. BOOL NEAR WriteTTYBlock( HWND, LPSTR, int ) ;
  232. int NEAR ReadCommBlock( HWND, LPSTR, int ) ;
  233. BOOL NEAR WriteCommByte( HWND, BYTE ) ;
  234. BOOL NEAR MoveTTYCursor( HWND ) ;
  235. BOOL NEAR OpenConnection( HWND ) ;
  236. BOOL NEAR SetupConnection( HWND ) ;
  237. BOOL NEAR CloseConnection( HWND ) ;
  238. BOOL NEAR ProcessCOMMNotification( HWND, WPARAM, LPARAM ) ;
  239. VOID NEAR GoModalDialogBoxParam( HINSTANCE, LPCSTR, HWND, DLGPROC, LPARAM ) ;
  240. VOID NEAR FillComboBox( HINSTANCE, HWND, int, DWORD NEAR *, WORD, DWORD ) ;
  241. BOOL NEAR SelectTTYFont( HWND ) ;
  242. BOOL NEAR SettingsDlgInit( HWND ) ;
  243. BOOL NEAR SettingsDlgTerm( HWND ) ;
  244.  
  245. // function prototypes (public)
  246.  
  247. LRESULT FAR PASCAL TTYWndProc( HWND, UINT, WPARAM, LPARAM ) ;
  248. BOOL FAR PASCAL AboutDlgProc( HWND, UINT, WPARAM, LPARAM ) ;
  249. BOOL FAR PASCAL SettingsDlgProc( HWND, UINT, WPARAM, LPARAM ) ;
  250.  
  251. #ifdef WIN32
  252. DWORD FAR PASCAL CommWatchProc( LPSTR ) ;
  253. #endif
  254.  
  255. //---------------------------------------------------------------------------
  256. //  End of File: tty.h
  257. //---------------------------------------------------------------------------
  258.